"""
数据库连接配置
"""
import os
from typing import Dict, Any

class DatabaseConfig:
    """数据库配置类"""
    
    def __init__(self):
        self.connections = {
            'default': {
                'host': os.getenv('DB_HOST', 'localhost'),
                'port': int(os.getenv('DB_PORT', '5432')),
                'database': os.getenv('DB_NAME', 'dify'),
                'username': os.getenv('DB_USERNAME', 'postgres'),
                'password': os.getenv('DB_PASSWORD', 'difyai123456'),
                'driver': 'postgresql'
            },
            'analysis': {
                'host': os.getenv('ANALYSIS_DB_HOST', 'localhost'),
                'port': int(os.getenv('ANALYSIS_DB_PORT', '5432')),
                'database': os.getenv('ANALYSIS_DB_NAME', 'analysis'),
                'username': os.getenv('ANALYSIS_DB_USERNAME', 'postgres'),
                'password': os.getenv('ANALYSIS_DB_PASSWORD', 'difyai123456'),
                'driver': 'postgresql'
            }
        }
    
    def get_connection_string(self, connection_name: str = 'default') -> str:
        """获取数据库连接字符串"""
        config = self.connections.get(connection_name)
        if not config:
            raise ValueError(f"未找到连接配置: {connection_name}")
        
        return f"{config['driver']}://{config['username']}:{config['password']}@{config['host']}:{config['port']}/{config['database']}"
    
    def get_connection_config(self, connection_name: str = 'default') -> Dict[str, Any]:
        """获取数据库连接配置"""
        config = self.connections.get(connection_name)
        if not config:
            raise ValueError(f"未找到连接配置: {connection_name}")
        
        return config.copy()

# 全局配置实例
db_config = DatabaseConfig() 